<template>
  <a-modal v-model="visible" title="审批" width="1500px" :footer="null">
    <a-card :bordered="false">
      <div>
        <a-form @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="6" :sm="6">
              <a-form-item label="姓名" :label-col="labelCol" :wrapper-col="wrapperCol">
                <a-input v-model="queryParam.name" placeholder="请输入姓名" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="6">
              <a-form-item label="电话号码" :label-col="labelCol" :wrapper-col="wrapperCol">
                <a-input v-model="queryParam.mobile" placeholder="请输入电话号码" />
              </a-form-item>
          </a-col>
          <a-col :md="6" :sm="6">
              <a-form-item label="审核状态" :label-col="labelCol" :wrapper-col="wrapperCol">
                <z-dict-select-tag v-model="queryParam.status" placeholder="请选择" 
                    dictCode="APPROVAL_STATUS"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="6">
              <a-form-item>
                <a-button type="primary" icon="search" @click="searchQuery()">查询</a-button>
                <a-button type="primary" icon="reload" style="margin-left: 8px" @click="searchReset()">重置</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <vxe-grid
          id="salonApproval"
          ref="vxeTable"
          :row-config="{keyField:'id'}"
          v-bind="options"
          v-on="listeners"
      >
        <template #action="{ row }">
          <a @click="auditPass(row)">通过</a>
          <a-divider type="vertical" v-if="row.signIn != '1'" />
          <a @click="auditNoPass(row)" v-if="row.signIn != '1'" >驳回</a>
        </template>
      </vxe-grid>
    </a-card>
  </a-modal>
</template>

<script>
import { VxeTableMixin } from '@/mixins/VxeTableMixin'
import ZDictSelectTag from '@/components/dict/ZDictSelectTag'
import { postAction} from '@/services/manage'
import Criteria from '@/utils/criteria'
import { OPERATOR } from '@/store/mutation-types'
import { filterObj } from '@/utils/util'

export default {
  name: 'salonApproval',
  mixins: [VxeTableMixin],
  components: {
    ZDictSelectTag
  },
  data() {
    return {
      visible:false,
      columns: [
        {type: 'checkbox', width: 40, fixed: 'left'},
        {type: 'seq', width: 40, fixed: 'left'},
        {title: '手机号', field: 'mobile',width: 120},
        {title: '姓名', field: 'name',width: 100},
        {title: '性别', field: 'sex',width: 60},
        {title: '出生年月', field: 'birthMonth',width: 100},
        {title: '专业', field: 'speciality',width: 120},
        {title: '学位', field: 'degree',width: 100},
        {title: '职称', field: 'title',width: 100},
        {title: '毕业院校', field: 'graduation',width: 150},
        {title: '工作单位', field: 'workUnit',width: 150},
        {title: '审核状态', field: 'status',width: 100,formatter: 'dictText'},
        {title: '审核时间', field: 'auditTime'},
        {title: '操作', field: 'operation', width: 120, fixed: 'right', slots: {default: 'action'}}
      ],
      url: {
        list: '/salon/applicants/v1/page',
        pass: '/salon/applicants/v1/pass',
        nopass: '/salon/applicants/v1/nopass'
      },
      elementId: 'apment:SalonApproval:export',
      customTableToolbar: {
        import: false,
        buttons: [
          { buttonRender: {
            name: 'VxeToolbarAdd',
            events: { click: this.BatchAuditPass },
            toolbarProps: {
              title: '审核通过',
              icon: 'check-circle'
            }
          }},
          { buttonRender: {
            name: 'VxeToolbarAdd',
            events: { click: this.BatchAuditNoPass },
            toolbarProps: {
              title: '驳回',
              icon: 'stop'
            }
          }}
        ]
      },
      proxyConfig: {
        autoLoad: true// 初始化自动请求数据
      }
    }
  },
  methods:{
    getQueryParams(record) {
      if(record){
        this.recordInfo = record
      }
      // 获取查询条件
      const queryParam = new Criteria()
      queryParam.addCriterions(Object.assign({}, filterObj(this.queryParam), this.filters), OPERATOR.LIKE_START)// 过滤参数转换为jpa支持格式
      //会议信息主键
      queryParam.addCriterions({ 'salonId': this.recordInfo.id }, OPERATOR.EQ)
      this.isorter && queryParam.addOrder(this.isorter)// 增加排序规则
      var param = Object.assign({}, { criteria: queryParam.getEncode() })
      param.pageNo = this.ipagination.currentPage
      param.pageSize = this.ipagination.pageSize
      return filterObj(param);
    },
    auditPass(row) {
      this.$confirm({
        title: '温馨提示',
        content: '确定要通过该申请吗?',
        onOk: () => {
          this.loading = true
          postAction(this.url.pass,{ids: row.id}).then(res => {
            if (res.success) {
              this.$message.success(res.message)
              this.loadData()
            }
          }).finally(() => {
            this.loading = false
          })
        }
      })
    },
    auditNoPass(row) {
      this.$confirm({
        title: '温馨提示',
        content: '确定要驳回该申请吗?',
        onOk: () => {
          this.loading = true
          postAction(this.url.nopass,{ids: row.id}).then(res => {
            if (res.success) {
              this.$message.success(res.message)
              this.loadData()
            }
          }).finally(() => {
            this.loading = false
          })
        }
      })
    },
    BatchAuditPass() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！')
        return
      } else {
        this.$confirm({
          title: '温馨提示',
          content: '确定要批量通过所选申请吗?',
          onOk: () => {
            this.loading = true
            postAction(this.url.pass,{ids: this.selectedRowKeys.join()}).then((res) => {
              if (res.success) {
                this.$message.success(res.message)
                this.loadData()
                this.onClearSelected()
              }
            }).finally(() => {
              this.loading = false
            })
          }
        })
      }
    },
    BatchAuditNoPass() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！')
        return
      } else {
        this.$confirm({
          title: '温馨提示',
          content: '确定要批量通过所选申请吗?',
          onOk: () => {
            this.loading = true
            postAction(this.url.nopass,{ids: this.selectedRowKeys.join()}).then((res) => {
              if (res.success) {
                this.$message.success(res.message)
                this.loadData()
                this.onClearSelected()
              }
            }).finally(() => {
              this.loading = false
            })
          }
        })
      }
    },
  }
}
</script>